package main

import "github.com/spf13/cobra"

var (
	peerAddress string
	serviceName string
	mspid string
	ordererAddress string
	userCert string
	userKey string
	tlsCaCert string
	cardName  string
	channelid string
	affiliation string
	attributes string
	userName string
	userSecret string   // secret is required when enroll user cryptocerts
	caURL string  // url of CA, like 'http://localhost:7054'
	adminPath string
	adminCert string
	adminKey string
)

var rootCmd = &cobra.Command{}

var statusCmd = &cobra.Command{
	Use:"status",
	Short:"peer status",
	Run: status,
}

var channelCmd = &cobra.Command{
	Use: "channel",
	Short:"channel create, list or join",
}

var channelCreateCmd = &cobra.Command{
	Use: "create",
	Short:"create channel",
	Run:channelCreate,
}

var channelListCmd = &cobra.Command{
	Use: "list",
	Short:"list channel",
	Run: channelList,
}

var createUserCmd = &cobra.Command{
	Use: "enroll",
	Short: "enroll user client to access fabric network",
	Run: createUser,
}

var chaincodeCmd = &cobra.Command{}

func init() {
	statusCmd.Flags().StringVar(&peerAddress, "peerAddress", "", "")
	statusCmd.Flags().StringVar(&serviceName, "sn", "", "")
	statusCmd.Flags().StringVar(&userCert, "user.cert", "", "")
	statusCmd.Flags().StringVar(&userKey, "user.key", "", "")
	statusCmd.Flags().StringVar(&tlsCaCert, "tlscert", "", "")
	statusCmd.Flags().StringVar(&cardName, "card", "", "")

	channelListCmd.Flags().StringVar(&peerAddress, "peerAddress", "", "")
	channelListCmd.Flags().StringVar(&serviceName, "sn", "", "")
	channelListCmd.Flags().StringVar(&mspid, "mspid", "", "")
	channelListCmd.Flags().StringVar(&cardName, "card", "", "")
	channelListCmd.Flags().StringVar(&userCert, "user.cert", "", "")
	channelListCmd.Flags().StringVar(&userKey, "user.key", "", "")
	channelListCmd.Flags().StringVar(&tlsCaCert, "tlscert", "", "")

	createUserCmd.Flags().StringVarP(&userName, "name", "n", "", "")
	createUserCmd.Flags().StringVarP(&userSecret, "secret", "s", "", "")
	createUserCmd.Flags().StringVarP(&affiliation, "affiliation", "", "", "")
	createUserCmd.Flags().StringVarP(&caURL, "url", "u", "", "")
	createUserCmd.Flags().StringVarP(&adminCert, "admin.cert", "", "", "")
	createUserCmd.Flags().StringVarP(&adminKey, "admin.key", "", "", "")
	//createUserCmd.Flags().StringVarP()

	channelCmd.AddCommand(channelCreateCmd)
	channelCmd.AddCommand(channelListCmd)

	rootCmd.AddCommand(statusCmd)
	rootCmd.AddCommand(channelCmd)
	rootCmd.AddCommand(createUserCmd)
}

func main() {
	rootCmd.Execute()
}